#!/usr/bin/perl
## Web::Scraper, RSSLite
## Web::Scraper - Web Scraping Toolkit inspired by Scrapi
use strict;
use warnings;
use lib qw( /Lib );
use URI;
use Web::Scraper;
use XML::RSS;
use CGI;
use Data::Dumper;

my $url ="http://www.soccerline.co.kr/news_list/index.php?menu=main";
my $uri = URI->new($url);
my $rss = new XML::RSS(version => '2.0', encoding=>"utf-8");
my $cgi = CGI->new();
$cgi->charset('utf-8');

## WEB::Scraper
my $scrp = scraper {
    process "td.te2>a",
    "items[]" => {
    	'title' => 'TEXT',
    	'link' => '@href',
    };
};
 
my $res = $scrp->scrape( $uri );
##print Dumper ( $res ); exit;

$rss->channel(
	title        => "SoccerLine News",
	link         => $url,
	description  => sprintf( "RSS Feed for %s ( %s )", $url, scalar(localtime) ) ,
);

foreach my $item ( @{$res->{items}} ) {
	if ( $item->{link} =~ m!menu=viewbody!i ) {
		$rss->add_item(
			title => $item->{title},
			link => $item->{link},
			guid => $item->{link},
		);
	}
}

print $cgi->header("text/xml"), $rss->as_string;

